import { createApp } from "vue";
import MessageIndex from '../components/MessageIndex.vue'
export type MessageType = 'success' | 'error' | 'default'
const createMessage = (message: string, type: MessageType, timeout = 2000) => {
    //创建实例
    //第一个参数：根节点
    //第二个参数：传给根节点的pops
    const messageInstance = createApp(MessageIndex, { message, type })
    //创建节点
    const mountNode = document.createElement('div')
    mountNode.id = 'message'
    //挂载组件到div
    document.body.appendChild(mountNode)
    messageInstance.mount(mountNode)
    setTimeout(() => {
        //卸载组件
        messageInstance.unmount()
        //卸载节点
        document.body.removeChild(mountNode)
    },timeout)
}
export default createMessage